import {
  ApiProperty,
  IntersectionType,
  OmitType,
  PartialType,
  PickType,
} from '@nestjs/swagger';
import { IsInt, IsString } from 'class-validator';
import { FindListDto } from 'src/modules/find-list.dto';

export class LogDto {
  @IsInt()
  @ApiProperty({ type: Number, description: 'id' })
  readonly id: number;

  @IsString()
  @ApiProperty({ type: String, description: '请求方式' })
  public method: string;

  @ApiProperty({ type: String, description: '地址' })
  public url: string;

  @ApiProperty({ type: String, description: 'ip' })
  public ip: string;

  @ApiProperty({ type: String, description: '请求参数' })
  public data: string;

  @ApiProperty({ type: String, description: 'http状态码' })
  public status: string;

  @ApiProperty({ type: Date, description: '时间', default: null })
  readonly time: Date;

  @IsString()
  @ApiProperty({
    type: String,
    description: '操作人',
    default: null,
  })
  readonly operator: string;
}
export class FindLogListDto extends IntersectionType(
  PartialType(FindListDto),
  PartialType(PickType(LogDto, ['method', 'operator'] as const)),
) {}

export class CreateLogDto extends PartialType(OmitType(LogDto, ['id'])) {}
